/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 7/24/14
 * Time: 7:30 AM
 * To change this template use File | Settings | File Templates.
 */
package com.societyGames.utility
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;

public class LoaderErrorHandler
{
  public static function addListeners(loader:Loader):void
  {
    var loaderInfo:LoaderInfo = loader.contentLoaderInfo;
    loaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    loaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus, false, 0, true);
    loaderInfo.addEventListener(Event.INIT, onInit, false, 0, true);
    loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    loaderInfo.addEventListener(Event.OPEN, onOpen, false, 0, true);
    loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress, false, 0, true);
    loaderInfo.addEventListener(Event.UNLOAD, onUnload, false, 0, true);
  }

  public static function removeListeners(loader:Loader):void
  {
    var loaderInfo:LoaderInfo = loader.contentLoaderInfo;
    loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
    loaderInfo.removeEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);
    loaderInfo.removeEventListener(Event.INIT, onInit);
    loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
    loaderInfo.removeEventListener(Event.OPEN, onOpen);
    loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
    loaderInfo.removeEventListener(Event.UNLOAD, onUnload);
  }

  private static function onComplete(event:Event):void
  {
    trace("onComplete");
  }

  private static function onHTTPStatus(event:Event):void
  {
    trace("onHTTPStatus");
  }

  private static function onInit(event:Event):void
  {
    trace("onInit");
  }

  private static function onIOError(event:Event):void
  {
    trace("onIOError");
  }

  private static function onOpen(event:Event):void
  {
    trace("onOpen");
  }

  private static function onProgress(event:Event):void
  {
    trace("onProgress");
  }

  private static function onUnload(event:Event):void
  {
    trace("onUnload");
  }
}
}
